<?php
namespace BLL\DAO;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 * Description of ApplicationDataNode
 *
 * @author David Wu
*/
class ApplicationDataModel extends Model{
    //put your code here
    
    protected $schema;
    public function __construct($schema,array $attributes = array()){
        parent::__construct($attributes);
        if ($schema) {
            $this->schema = $schema;
            $this->table = $schema->realTableName();
        }
    }
    public function findByID($id, $columns = array('*')){
        if (is_array($id) && empty($id)) {
            return new Collection;
        }
        $ret = $this->newQuery()->find($id, $columns);
        if($ret){
            $ret->schema = $this->schema;
            $ret->table = $this->table;
        }
        return $ret;
    }
    public static function LoadFromID($schema,$id,$columns = array('*')){
       $model = new ApplicationDataModel($schema);
       return $model->findByID($id);
    }
    public function findByMaster($masterid, $columns = array('*')){
        $ret = $this->newQuery()->where("master_id","=",$masterid)->get();
        $table = $this->table;
        foreach ($ret as $row){
            $row->schema = $this->schema;
            $row->table = $this->table;
        }
        return $ret;
    }
    public function findDetails($node, $columns = array('*')){
        $model = new ApplicationDataModel($this->schema->getDetailNode($node));
        $ret = $model->findByMaster($this[$this->primaryKey], $columns = array('*'));
        return $ret;
    }
    
}
